/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import Constructor.Common;
import Model.Model_User_Quest;
import Util.DataUtil;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author TuanDat
 */
public class DAO_UserQuest {
    
    public ArrayList<Model_User_Quest> get_AllUser_QuestbyUserID(int ID){
        ArrayList<Model_User_Quest> list_User_Quest = new ArrayList<Model_User_Quest>();
        try {
            CallableStatement csmt = DataUtil.getconnect().prepareCall("{Call sp_GetAllUser_QuestbyUserID(?)}");
            csmt.setInt("ID", ID);
            ResultSet rs = csmt.executeQuery();
            while (rs.next()) {
                Model_User_Quest user_quest = new Model_User_Quest();
                user_quest.setUser_id(rs.getString("User_ID"));
                user_quest.setQuestion_id(rs.getString("Question_ID"));
                user_quest.setLast_update(rs.getString("Last_Update"));

                list_User_Quest.add(user_quest);
            }
        } catch (SQLException ex) {
            Logger.getLogger(DAO_Question.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return list_User_Quest;
    }
    
    public boolean insertUser_Quest(Model_User_Quest user_qest){
        try {
            CallableStatement csmt = DataUtil.getconnect().prepareCall("{call sp_insertUser_Quest(?,?)}");
            csmt.setInt("User_ID", Integer.parseInt(user_qest.getUser_id()));
            csmt.setInt("Question_ID", Integer.parseInt(user_qest.getQuestion_id()));
            csmt.execute();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DAO_Question.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
}
